home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Examples / Class2.e < prev    next >
Text File  |  2002-10-28  |  5KB  |  159 lines

  1. OPT PREPROCESS
  2.  
  3. MODULE 'graphics/gfx','graphics/rastport',
  4.        'feelin','libraries/feelin','a4'
  5.  
  6. -> Here is the beginning of our simple new class...
  7.  
  8. CONST FM_Strobo = FCCM_BASE
  9.  
  10. OBJECT localobjectdata
  11.    signalhandler:feelinSignalHandler
  12. ENDOBJECT
  13.  
  14. PROC main()
  15.    DEF c,w,
  16.        fcc:PTR TO feelinClass
  17.  
  18.    sys_SGlob()
  19.  
  20.    IF feelinbase := OpenLibrary('feelin.library',FV_VERSION)
  21.  
  22. /*
  23. Create the new custom class with a call to F_CreateClass().
  24.  
  25. This function returns a feelinClass structure. You must use class.id as  ID
  26. to  create  instance  of  your  custom class. This ID is unique and made by
  27. F_CreateClass() when ID is NIL.
  28. */
  29.  
  30.       IF fcc := F_CreateClassA([FA_SuperID,     FC_Area,
  31.                                 FA_DataSize,    SIZEOF localobjectdata,
  32.                                 FA_Dispatcher,  {myDispatcher},
  33.                                 NIL])
  34.          c := ClientObject,
  35.             FA_Client_Title,        'Class2',
  36.             FA_Client_Version,      '$VER: Class2 0.02 (22.10.01)',
  37.             FA_Client_Copyright,    '© 2001 by Laviale Olivier',
  38.             FA_Client_Author,       'Laviale Olivier (lotan9@aol.com)',
  39.             FA_Client_Description,  'Tutorial on Client.AddInputHandler()',
  40.             FA_Client_Base,         'CLASS2',
  41.  
  42.             Child, w := WindowObject, FA_Window_Title, 'Crazy colors using Client.AddInputHandler()', FA_ID, "CLS2",
  43.                Child, VGroup,
  44.                   Child, HGroup,
  45.                      Child, F_NewObjA(fcc.id,[GaugeFrame, DontChain, NIL]),
  46.                      Child, F_NewObjA(fcc.id,[GaugeFrame, DontChain, NIL]),
  47.                   End,
  48.  
  49.                   Child, HGroup,
  50.                      Child, F_NewObjA(fcc.id,[GaugeFrame, DontChain, NIL]),
  51.                      Child, F_NewObjA(fcc.id,[GaugeFrame, DontChain, NIL]),
  52.                   End,
  53.                End,
  54.             End,
  55.          End
  56.  
  57.          IF c
  58.             F_DoA(w,FM_Notify,[FA_Window_CloseRequest,TRUE, c,2,FM_Client_ReturnID,FV_Client_Quit])
  59.             F_Set(w,FA_Window_Open,TRUE)
  60.  
  61.             F_DoA(c,FM_Client_Run,NIL)
  62.  
  63.             F_DisposeObj(c)
  64.          ENDIF
  65.  
  66.          F_RemoveClass(fcc)
  67.       ELSE
  68.          WriteF('Unable to create custom class.\n')
  69.       ENDIF
  70.  
  71.       CloseLibrary(feelinbase)
  72.    ELSE
  73.       WriteF('Failed to open feelin.library.\n')
  74.    ENDIF
  75. ENDPROC
  76.  
  77. PROC myDispatcher(cl=A2:PTR TO feelinClass,obj=A0:PTR TO feelinObject,method=D0,args=A1:PTR TO LONG)
  78.    DEF data:PTR TO localobjectdata
  79.  
  80.    sys_RGlob() ; data := INST_DATA(cl,obj)
  81. /*
  82. Here comes the dispatcher for our custom class. Unknown/unused methods  are
  83. passed to the superclass immediately.
  84. */
  85.  
  86.    SELECT method
  87.       CASE FM_New         ; RETURN mNew       (cl,obj,data,args)
  88.  
  89.       CASE FM_Show        ; RETURN mShow      (cl,obj,data)
  90.       CASE FM_Hide        ;        mHide      (cl,obj,data)
  91.       CASE FM_AskMinMax   ; RETURN mAskMinMax (cl,obj)
  92.       CASE FM_Draw        ; RETURN mDraw      (cl,obj,args)
  93.  
  94.       CASE FM_Strobo      ; RETURN F_Draw(obj,FF_Draw_Update) BUT TRUE
  95.  
  96.       DEFAULT             ; RETURN F_SuperDoA(cl,obj,method,args)
  97.    ENDSELECT
  98. ENDPROC
  99.  
  100. PROC mNew(cl,obj:PTR TO feelinObject,data:PTR TO localobjectdata,args)
  101.    data.signalhandler.object := obj
  102.    data.signalhandler.method := FM_Strobo
  103.    data.signalhandler.flags  := FF_SignalHandler_Timer
  104.    data.signalhandler.secs   := 0
  105.    data.signalhandler.micros := 30000
  106. ENDPROC F_SuperDoA(cl,obj,FM_New,args)
  107. PROC mAskMinMax(cl,obj:PTR TO feelinObject)
  108. /*
  109. AskMinMax method will be called before the  window  is  opened  and  before
  110. layout  takes place. We need to tell Feelin the minimum and maximum size of
  111. our object. Note that we indeed need to *add* these values,  not  just  set
  112. them !
  113. */
  114.  
  115.    _minw(obj) += 30
  116.    _minh(obj) += 30
  117.  
  118. /*
  119. Now call our superclass. Area.fcc will handle everything,  taking  care  of
  120. FA_FixedXxx, FA_MinXxx and FA_MaxXxx.
  121. */
  122.  
  123.    F_SuperDoA(cl,obj,FM_AskMinMax,NIL)
  124. ENDPROC
  125. PROC mDraw(cl,obj:PTR TO feelinObject,d:PTR TO FS_Draw)
  126. /*
  127. Draw method is called whenever  Feelin  feels  (obviously  ;-))  we  should
  128. render our object. This usually happens after layout is finished. Note: You
  129. may only render within the rectangle _mleft(obj), _mtop(obj), _mwidth(obj),
  130. _mheight(obj).
  131. */
  132.  
  133.    DEF rp:PTR TO rastport
  134.  
  135.    rp := _rp(obj)
  136.  
  137. /*
  138. let our superclass draw itself first, Area class would e.g. draw the  frame
  139. and clear the whole region. What it does exactly depends on flags.
  140. */
  141.  
  142.    F_SuperDoA(cl,obj,FM_Draw,d)
  143.  
  144.    _APen(Rnd(1 << rp.bitmap.depth) - 1)
  145.    _Boxf(_mx(obj),_my(obj),_mx2(obj),_my2(obj))
  146. ENDPROC
  147. PROC mShow(cl,obj:PTR TO feelinObject,data:PTR TO localobjectdata)
  148.    DEF sh
  149.  
  150.    F_SuperDoA(cl,obj,FM_Show,NIL)
  151.    F_DoA(_client(obj),FM_Client_AddSignalHandler,(sh := data.signalhandler) BUT {sh})
  152. ENDPROC
  153. PROC mHide(cl:PTR TO feelinClass,obj:PTR TO feelinObject,data:PTR TO localobjectdata)
  154.    DEF sh
  155.  
  156.    F_DoA(_client(obj),FM_Client_RemSignalHandler,(sh := data.signalhandler) BUT {sh})
  157.    F_SuperDoA(cl,obj,FM_Hide,NIL)
  158. ENDPROC 
  159.